<template>
  <el-config-provider :locale="locale" :size="size">
    <router-view></router-view>
  </el-config-provider>
</template>

<script setup lang="ts">
import { useGlobalStore } from "@/stores";
import { computed, onMounted } from "vue";
import { getBrowserLanguage } from "@/utils";
import { useI18n } from "vue-i18n";
import en from "element-plus/es/locale/lang/en";
import zhCn from "element-plus/es/locale/lang/zh-cn";
import type { LanguageType } from "@/typings";
import { useTheme } from "@/hooks/useTheme";

const useGlobal = useGlobalStore();
const i18n = useI18n();
const { initTheme } = useTheme();

initTheme();
onMounted(() => {
  const language = useGlobal.globalConfig.language ?? getBrowserLanguage();
  i18n.locale.value = language;
  useGlobal.globalConfig.language = language as LanguageType;
});

const locale = computed(() => {
  if (useGlobal.globalConfig.language == "zh") return zhCn;
  if (useGlobal.globalConfig.language == "en") return en;
  return getBrowserLanguage() == "zh" ? zhCn : en;
});
/**
 * @description 计算布局大小
 */
const size = computed(() => useGlobal.globalConfig.assemblySize);
</script>
